<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<link rel="stylesheet" href="../../res/layui/css/layui.css" media="all">
<script type="text/javascript" src="../../res/js/jquery-3.1.1.min.js"></script>
<script src="../../res/layui/layui.js"></script>
<script src="../../res/js/Tools.js"></script>
<body>
<form class="layui-form" action="" lay-filter="example" id="example">
    <input type="hidden" name="schemeId" id="schemeId">
    <input type="hidden" name="saId" id="saId">

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">申请理由</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入内容" class="layui-textarea"  name="applyForExp" id="applyForExp" lay-verify="required"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo">立即提交</button>
        </div>
    </div>
</form>
<script>
    layui.use('form',function(){

        var form = layui.form;
        var schemeId = getQueryString("schemeId");
        var saId = getQueryString("schemeId");
        $("#schemeId").val(schemeId);
        $("#saId").val(saId);
        form.on('submit(demo)',function(obj){
           var url="../../atsScheme/insertAdvice";
           var formdata = new FormData(document.getElementById("example"));


            if(schemeId!=null){
                $.ajax({
                    url:url,
                    type:"post",
                    data:formdata,
                    async:false, // 全局同步
                    processData:false,
                    contentType:false,
                    dataType:"json",
                    success:function(obj){
                        alert(obj.num);
                        if(obj.num==1){
                            layer.msg('增加成功',{
                                icon:1,
                                time:1000,
                            },function(){
                                var indexs = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(indexs);
                                parent.table2.reload();
                            });
                        }else{
                            layer.msg("增加失败");
                        }
                    },
                    error:function(e){
                        alert("失败");
                    }
                });
            }
          return false;
        });

    });
</script>
</body>
</html>